//index.js
//获取应用实例
const app = getApp()
const $ = app.globalData
Page({
	data: {
		imgUrls: [],
		miaosha: [],
		model: [],
		hotList: [],
		sousuo: '',
		indexAdBg:true,
		content: '暂无通告，气不气',
	},
	indexAdBg:function(){
		this.setData({
			indexAdBg:false
		})
	},
	loop:function(){
		wx.navigateTo({
			url:"indexList/indexList"
		})
	},
	spike: function() {
		wx.navigateTo({
			url: "../spike/spike"
		})
	},
	// 搜索
	sousuo: function(e) {
		console.log(e.detail.value)
		this.setData({
			sousuo: e.detail.value
		})
	},
	sousuobut:function(){
		var that = this
		if(that.data.sousuo != ''){
			wx.navigateTo({
				url:'/pages/shopping/shoplist/shoplist?tabone=-1&tabtwo=-1&name='+that.data.sousuo
			})
		}
	},
	// 轮播图跳转
	bannerClick:function(e){
		var banindex = e.currentTarget.dataset.index
		var that = this
		var thatinfo = that.data.imgUrls[banindex]
		if(thatinfo.state == 1){
			wx.navigateTo({
				url: "/pages/shopping/details/details?id=" + thatinfo.goodsid + "&goodslib=0"
			})
		}else if(thatinfo.state == 2){
			
		}
	},
	// 专栏
	zhuanlan:function(e){
		var thisid = e.currentTarget.dataset.id
		wx.navigateTo({
			url:'/pages/shopping/shoplistzl/shoplist?id='+thisid
		})
	},
	clickGoods: function(data) {
		var thisid = data.currentTarget.dataset.id
		wx.navigateTo({
			url: "/pages/shopping/business/business?id=" + thisid
		})
	},
	pingtaigoods: function(data) {
		var thisid = data.currentTarget.dataset.id
		wx.navigateTo({
			url: "/pages/shopping/details/details?id=" + thisid + "&goodslib=0"
		})
	},
	//事件处理函数
	onLoad: function() {
		$.haveYouLanded()
		var that = this
		var isFir = wx.getStorageSync("isFirst");
		if (!isFir) {
			wx.redirectTo({
				url: '/pages/guide/guide'
			})
		}
		// 获取数据
		wx.request({
			url: $.AdminUrl + "/YApi/getIndex",
			success: function(data) {
				wx.stopPullDownRefresh();
				var dataa = data.data.obj
				console.log(data)
				that.setData({
					imgUrls: dataa.bannerList,
					model: dataa.salemodelList,
					miaosha: dataa.seckillList,
					hotList: dataa.hotList,
					information:dataa.information,
					sys:dataa.sys
				})
			}
		})
		wx.getStorage({
			key: "userinfo",
			success: (res) => {
				wx.request({
					url: $.AdminUrl + "/YApi/getMyShopcar",
					data: {
						customerid: res.data.id
					},
					success: (res) => {
						that.setData({
							shoplist: res.data.obj
						})
					}
				})
			}
		})
		wx.stopPullDownRefresh();
	},
	// 上拉刷新
	onPullDownRefresh() {
		this.onLoad()
		console.log(12)
	  },
	// 附近门店
	navclick4: function() {
		wx.navigateTo({
			url: "../nearby/nearby"
		})
	},
	onShow() {
		var that = this
		wx.getStorage({
			key: "userinfo",
			success: (res) => {
				wx.request({
					url: $.AdminUrl + "/YApi/getMyShopcar",
					data: {
						customerid: res.data.id
					},
					success: (res) => {
						that.setData({
							shoplist: res.data.obj
						})
					}
				})
			}
		})
	},
	// 首页购物车
	indexcart: function() {
		wx.switchTab({
			url: "../shoppingcart/shoppingcart"
		})
	},
	// 代理商城
	daili: function() {
		$.shoptype = 1
		$.shopstatr = true
		wx.switchTab({
			url: "../shopping/shopping"
		})
	},
	jifen: function() {
		$.shoptype = 4
		$.shopstatr = true
		wx.navigateTo({
			url: "../shopping/shoplist/shoplist?tabone=-1&tabtwo=-1"
		})
	},
	libao: function() {
		$.shoptype = 2
		$.shopstatr = true
		wx.navigateTo({
			url: "../shopping/shoplist/shoplist?tabone=-1&tabtwo=-1"
		})
	},
	zlibao: function() {
		$.shoptype = 3
		$.shopstatr = true
		wx.navigateTo({
			url: "../shopping/shoplist/shoplist?tabone=-1&tabtwo=-1"
		})
	},
	// 分享转发
	onShareAppMessage: function() {
		var userinfo = wx.getStorageSync('userinfo')
		return {
			title: '优悦购生活管家',
			path: '/pages/index/index?userid='+userinfo.loginname,
			success: (res) => {
				console.log("转发成功", res);
			},
			fail: (res) => {
				console.log("转发失败", res);
			}
		}
	}
})

// 首页数据对接完成跳转未做
